#include "StdAfx.h"
#include "CircuitAnnotation.h"


CCircuitAnnotation::CCircuitAnnotation(void)
{
	m_dblPosX = 0;
	m_dblPosY = 0;
	m_rotateAngle = 0;
	m_dblColor[0] = 0;
	m_dblColor[1] = 0;
	m_dblColor[2] = 0;
	m_circuitFont = NULL;
	m_bSelected = false;
	m_szContent = _T("");
}

CCircuitAnnotation::CCircuitAnnotation(const CCircuitAnnotation *pEntityObj)
	: CCircuitUnit(pEntityObj)
{
	m_dblPosX = pEntityObj->GetPosX();
	m_dblPosY = pEntityObj->GetPosY();
	m_rotateAngle = pEntityObj->GetRotateAngle();
	m_dblColor[0] = pEntityObj->GetColorR();
	m_dblColor[1] = pEntityObj->GetColorG();
	m_dblColor[2] = pEntityObj->GetColorB();
	m_circuitFont = pEntityObj->GetFont()->Clone();
	m_bSelected = pEntityObj->IsSelect();
	m_szContent = pEntityObj->GetContent();
}

CCircuitAnnotation::CCircuitAnnotation(CICircuit *pParentEnt)
	: CCircuitUnit(pParentEnt)
{
	m_dblPosX = 0;
	m_dblPosY = 0;
	m_rotateAngle = 0;
	m_dblColor[0] = 0;
	m_dblColor[1] = 0;
	m_dblColor[2] = 0;
	m_circuitFont = NULL;
	m_bSelected = false;
	m_szContent = _T("");
}

CCircuitAnnotation::~CCircuitAnnotation(void)
{
	Clear();
}

void CCircuitAnnotation::Serialize(CArchive & ar)
{
	if (ar.IsStoring())
	{
		ar << m_dblPosX;
		ar << m_dblPosY;
		ar << m_rotateAngle;
		ar << m_dblColor[0];
		ar << m_dblColor[1];
		ar << m_dblColor[2];
		m_circuitFont->Serialize(ar);
		ar << m_bSelected;
		CObj::WriteString(ar, m_szContent);
	}
	else
	{
		ar >> m_dblPosX;
		ar >> m_dblPosY;
		ar >> m_rotateAngle;
		ar >> m_dblColor[0];
		ar >> m_dblColor[1];
		ar >> m_dblColor[2];
		m_circuitFont = new CCircuitFont();
		m_circuitFont->Serialize(ar);
		ar >> m_bSelected;
		CObj::ReadString(ar, m_szContent);
	}

	CCircuitUnit::Serialize(ar);
}

CObj *CCircuitAnnotation::Clone() const
{
	return new CCircuitAnnotation(this);
}

void CCircuitAnnotation::Transform(const CMatrix transf)
{

}

bool CCircuitAnnotation::GetBox(double & dblLeft, double & dblBottom, double & dblRight, double & dblTop) const
{
	return false;
}

void CCircuitAnnotation::Clear()
{
	if (m_circuitFont)
	{
		delete m_circuitFont;
		m_circuitFont = NULL;
	}
}

void CCircuitAnnotation::CopyDisplayObj(long lSourceLayerId, long lDestLayerId)
{
	CEntityObj::CopyDisplayObj(lSourceLayerId, lDestLayerId);
}

void CCircuitAnnotation::DeleteDisplayObj(long lLayerId)
{
	CEntityObj::DeleteDisplayObj(lLayerId);
}

CDisplayObj *CCircuitAnnotation::CreateDisplayObj(long lLayerId)
{
	CCircuitAnnotationDisObj *pAnnDis = new CCircuitAnnotationDisObj(this);
	pAnnDis->SetLayerId(lLayerId);
	return pAnnDis;
}

void CCircuitAnnotation::CalcBox()
{
	if (m_circuitFont)
	{
// 		int len = m_szContent.GetLength();
// 		double dblTextHeight = m_circuitFont->GetSize();
// 		double dblTextWidth = dblTextHeight*len;
// 		m_minX = m_dblPosX - 0.5*dblTextWidth;
// 		m_minY = m_dblPosY - 0.5*dblTextHeight;
// 		m_maxX = m_dblPosX + 0.5*dblTextWidth;
// 		m_maxY = m_dblPosY + 0.5*dblTextHeight;
		int len = m_szContent.GetLength();
		double dblTextHeight = m_circuitFont->GetSize();
		double dblTextWidth = dblTextHeight*len;
		m_minX = m_dblPosX;
		m_minY = m_dblPosY;
		m_maxX = m_dblPosX + 0.4*dblTextWidth;
		m_maxY = m_dblPosY + dblTextHeight;
	}
}

eCircuitUnitEntType CCircuitAnnotation::GetUnitType() const
{
	return CIRCUIT_ANNOTATION;
}

double CCircuitAnnotation::GetRotateAngle() const
{
	return m_rotateAngle ;
}
double CCircuitAnnotation::GetColorR() const
{
	return m_dblColor[0] ;
}

double CCircuitAnnotation::GetColorG() const
{
	return m_dblColor[1];
}

double CCircuitAnnotation::GetColorB() const
{
	return m_dblColor[2];
}

CCircuitFont *CCircuitAnnotation::GetFont() const
{
	return m_circuitFont;
}

bool CCircuitAnnotation::IsSelect() const
{
	return m_bSelected;
}

double CCircuitAnnotation::GetPosX() const
{
	return m_dblPosX;
}

double CCircuitAnnotation::GetPosY() const
{
	return m_dblPosY;
}

CString CCircuitAnnotation::GetContent() const
{
	return m_szContent;
}

void CCircuitAnnotation::SetRotateAngle(double angle) 
{
	m_rotateAngle = angle;
}

void CCircuitAnnotation::SetColorR(double colR) 
{
	m_dblColor[0] = colR;
}

void CCircuitAnnotation::SetColorG(double colG)
{
	m_dblColor[1] = colG;
}

void CCircuitAnnotation::SetColorB(double colB)
{
	m_dblColor[2] = colB;
}
void CCircuitAnnotation::SetFont(CCircuitFont * pFont) 
{
	m_circuitFont = pFont;
}

void CCircuitAnnotation::SetSelect(bool bFlag)
{
	m_bSelected = bFlag;
}

void CCircuitAnnotation::SetPosX(double posX) 
{
	m_dblPosX = posX;
}

void CCircuitAnnotation::SetPosY(double posY) 
{
	m_dblPosY = posY;
}



void CCircuitAnnotation::SetContent( CString szContent)
{
	m_szContent = szContent;
}
